package com.cxrj.zhsq.noticeManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.cxrj.zhsq.noticeManage.entity.PropertyNotice;
import com.cxrj.zhsq.noticeManage.entity.PropertyNoticeType;
import com.cxrj.zhsq.noticeManage.service.PropertyNoticeService;

@RestController
public class PropertyNoticeController {

	@Resource
	private PropertyNoticeService propertyNoticeService;

	/**
	 * 分页查询通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyNotices", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectPropertyNotices(HttpServletRequest request, HttpServletResponse response) {
		return propertyNoticeService.seletePropertyNoticePage(request, response);
	}
	
	/**
	 * 分页查询通知类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyNoticeTypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectPropertyNoticeTypes(HttpServletRequest request, HttpServletResponse response) {
		return propertyNoticeService.seletePropertyNoticeTypePage(request, response);
	}

	/**
	 * 根据id查询通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyNoticeById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectPropertyNoticeById(String id, HttpServletRequest request) {
		return propertyNoticeService.selectPropertyNoticeById(id);
	}
	
	/**
	 * 根据id查询通知类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyNoticeTypeById", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> selectPropertyNoticeTypeById(String id, HttpServletRequest request) {
		return propertyNoticeService.selectPropertyNoticeTypeById(id);
	}

	/**
	 * 添加通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyNotice", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyNotice(PropertyNotice propertyNotice, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyNotice.setCommunityId(request.getSession().getAttribute("communityId").toString());
			propertyNotice.setS1(request.getSession().getAttribute("propertyUserAccount").toString());
			resultMap = propertyNoticeService.insertPropertyNotice(propertyNotice);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 添加通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "insertPropertyNoticeType", method = RequestMethod.POST)
	public Map<String, Object> insertPropertyNoticeType(PropertyNoticeType propertyNoticeType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			propertyNoticeType.setS1(request.getSession().getAttribute("communityId").toString());
			resultMap = propertyNoticeService.insertPropertyNoticeType(propertyNoticeType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}

	/**
	 * 修改通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyNotice", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyNotice(PropertyNotice propertyNotice, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyNoticeService.updatePropertyNotice(propertyNotice);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 修改通知
	 * 
	 * @return
	 */
	@RequestMapping(value = "updatePropertyNoticeType", method = RequestMethod.POST)
	public Map<String, Object> updatePropertyNoticeType(PropertyNoticeType propertyNoticeType, HttpServletRequest request) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			resultMap = propertyNoticeService.updatePropertyNoticeType(propertyNoticeType);
		} catch (Exception e) {
			resultMap.put("result", 0);
			e.printStackTrace();
		}
		return resultMap;
	}
	
	/**
	 * 查询使用通知类型
	 * 
	 * @return
	 */
	@RequestMapping(value = "selectPropertyNoticeTypeByAll", method = RequestMethod.POST)
	public Map<String, Object> selectPropertyNoticeTypeByAll(HttpServletRequest request) {
		return propertyNoticeService.selectPropertyNoticeTypeByAll(request);
	}
}
